<?php
/*
 * Created on Aug 12, 2009
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
class user_Form_BillingInfo extends Zend_Form
{

    protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );

    public function cluBuild($params)
    {
        // set the method for the display form to POST
        $this->setMethod('POST');
        if(!isset($params['number']))
//			$this->setAction('user/account/billing-info?id=' .$params['id']);
			$this->setAction($this->getView()->hvnUrl(array('action' => 'billing-info'),'account').'?id='.$params['id']);
		else
//			$this->setAction('user/account/billing-info?id=' .$params['id'] . '&number=' . $params['number']);
			$this->setAction($this->getView()->hvnUrl(array('action' => 'billing-info'),'account').'?id='.$params['id']. '&number=' . $params['number']);
		//common filters & validators for all fields
        $filterTrim = new Zend_Filter_StringTrim();
        $filterHtmlBody = new Clu_Filter_HtmlBody();
        
        //no-special-character validator
        $nscValidator = new Zend_Validate_Regex('/^[,A-Z0-9_\s\-]*$/i'); //alpha, num, space, -, _
        $nscValidator->setMessage(t(60), Zend_Validate_Regex::NOT_MATCH);
                
        //no-special-character validator
        $addressValidator = new Zend_Validate_Regex('/^[A-Z0-9_\s\-\/\+;,]*$/i'); //alpha, num, space, -, _
        $addressValidator->setMessage(t(60), Zend_Validate_Regex::NOT_MATCH);
        
        $validatorNotEmpty = new Zend_Validate_NotEmpty();
        $validatorNotEmpty->setMessage(t(418));

		//Full name
        $billingProfileName = new Zend_Form_Element_Text('billingProfileName', 
                         array('disableLoadDefaultDecorators' => true,
                               'class' => 'inputText'));
        
        $billingProfileName->addDecorators($this->_noDecorator)
              ->addValidator($nscValidator);
        $this->addElement($billingProfileName);
        
        //billing Address
        $fck = new Clu_Form_Element_FckEditor('billingAddress', array(
        		'fckOptions' => array (
        						'Height' => 100,
        						'Width'  => 450,
        						'ToolbarSet' => 'UserSignature'
        					)
       			 )
        );
        $fck->setLabel(t(429));
        $fck->addFilter($filterHtmlBody ); //TODO: if our people, maybe we don't need to filter
        $this->addElement($fck);
        
        $payment_method = new Zend_Form_Element_Select('payment_method', array('disableLoadDefaultDecorators' => true,
                                                                 'required' => false));
		$payment_method->addMultiOption('none','--'.t(138).'--')
               		->addMultiOption('cash',t(798))
               		->addMultiOption('creditcard',t(799))
               		->addMultiOption('sms',t(491))
               		->addMultiOption('atm',t(492))
               		->addMultiOption('other',t(711));
        $payment_method->addDecorators($this->_noDecorator);
        $this->addElement($payment_method);
        
        //account_type: Visa, Master Card, American Express, Dinner's club, JCB
        $account_type = new Zend_Form_Element_Select('account_type', array('disableLoadDefaultDecorators' => true,
                                                                 'required' => false));
		$account_type->addMultiOption('none','--'.t(138).'--')
               		->addMultiOption('visa',t(493))
               		->addMultiOption('masterCard',t(494))
               		->addMultiOption('AmericanExpress',t(495))
               		->addMultiOption('DinnerClub',t(496))
               		->addMultiOption('JCB',t(497));
        $account_type->addDecorators($this->_noDecorator);
        $this->addElement($account_type);
        
        // Bank
        $bank = new Zend_Form_Element_Select('bank',  array('disableLoadDefaultDecorators' => true,
                                                                 'required' => false));
        $mPlace = new place_Model_Place();
        $data = array('type' => array(84,86,87));
        $results = $mPlace->getListBank($data);
        $bank->addMultiOption('none', '--'.t(138).'--');
        foreach ($results as $k => $b) {
            $bank->addMultiOption($k, $b['name']);//p(trim($b['name'])));
        }
        $bank->addDecorators($this->_noDecorator);
        $this->addElement($bank);
        
		//account name
        $AccountName = new Zend_Form_Element_Text('account_name', 
                         array('disableLoadDefaultDecorators' => true,
                               'class' => 'inputText'));
        
        $AccountName->addDecorators($this->_noDecorator)
            	  ->addValidator($nscValidator);
        $this->addElement($AccountName);
        
        //account number
        $account_number = new Zend_Form_Element_Text('account_number', 
                         array('disableLoadDefaultDecorators' => true,
                               'class' => 'inputText'));
        
        $account_number->addDecorators($this->_noDecorator)
              ->addValidator($nscValidator);
        $this->addElement($account_number);
        
        //Expiry dater
        $expiryDate = new Zend_Form_Element_Text('expiry_date', 
                         array('disableLoadDefaultDecorators' => true,
                               'class' => 'inputText'));
        
        $expiryDate->addDecorators($this->_noDecorator)
              /*->addValidator($nscValidator)*/;
        $this->addElement($expiryDate);
        
        //Verification Code
        $verificationCode = new Zend_Form_Element_Text('verificationCode', 
                         array('disableLoadDefaultDecorators' => true,
                               'class' => 'inputText'));
        
        $verificationCode->addDecorators($this->_noDecorator)
              ->addValidator($nscValidator);
        $this->addElement($verificationCode);
        
        //submit
        // add the submit button
        $submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
                                                               'label' => t(59) ));
        $submit->addDecorators($this->_noDecorator);
        $this->addElement($submit);

    }
    
    public function populateForm($formName, $a)
    {
	 	foreach($a['billing'] as $k =>$v)
        {
        	if($a['number'] == $k)
	        	$dataDisplay = unserialize($v);
        }
        $data['billingProfileName'] = $dataDisplay['profileName'];
        $data['billingAddress'] = $dataDisplay['address'];
        $data['payment_method'] = $dataDisplay['payment_method'];
        if(isset($dataDisplay['expiry_date']))
        	$data['expiry_date'] = $dataDisplay['expiry_date'];
        if(isset($dataDisplay['verification_code']))
        	$data['verificationCode'] = $dataDisplay['verification_code'];
        $data['account_name'] = $dataDisplay['account_name'];
        $data['account_number'] = $dataDisplay['account_number'];
        if(isset($dataDisplay['bank']))
        	$data['bank'] = $dataDisplay['bank'];
        if(isset($dataDisplay['account_type']))
        	$data['account_type'] = $dataDisplay['account_type'];
        $this->populate($data);
    }
}
?>
